import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/4/21
 * Time:14:17
 **/
public class Main1 {
    /**
     * 每日一题-隔两个删数问题
     * 类似于约瑟夫环问题
     *
     * @param args
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        if (scanner.hasNext()) {
            int n = scanner.nextInt();
            Queue<Integer> queue = new LinkedList<>();
            for (int i = 0; i < n; i++) {
                queue.offer(i);//放进队列中
            }
            while (queue.size() > 1) {
                queue.offer(queue.poll());
                queue.offer(queue.poll());
                queue.poll();
            }
            System.out.println(queue.poll());
        }
    }
}
